package com.langsin.action;

import com.langsin.service.ProductService;
import com.langsin.service.impl.ProductServiceImpl;
import com.langsin.vo.Product;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class ProductUpdateAction extends HttpServlet{
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        response.setCharacterEncoding("UTF-8");
        String prodId = request.getParameter("prodId");
        ProductService service = new ProductServiceImpl();
        Product prod = service.queryProductById(prodId);
        if(prod == null){
            request.setAttribute("errorInfo","数据查询失败");
        }
        request.setAttribute("prodDetail",prod);
        request.getRequestDispatcher("./prodAdd.jsp").forward(request,response);
    }
}
